package com.jackeysun.app_common

import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.jackeysun.app_common.databinding.ActivityMain2Binding
import com.jackeysun.common.AbsAdapter
import com.jackeysun.common.IData
import com.jackeysun.common.AbsViewHolder

class MainActivity2 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val main2Binding = ActivityMain2Binding.inflate(layoutInflater)
        setContentView(main2Binding.root)

        val adapter = TestAdapter()
        adapter.layoutIds[0] = R.layout.item_view0
        adapter.layoutIds[1] = R.layout.item_view1

        val datas = mutableListOf<TestData>()
        for (i in 0..100) {
            datas.add(TestData("第${i}项", if (i % 2 == 0) 0 else 1))
        }
        adapter.data = datas
        main2Binding.rv.adapter = adapter
        main2Binding.rv.layoutManager = LinearLayoutManager(this)
    }
}

class TestData(private val content: String, private val type: Int) : IData<AbsViewHolder> {

    override fun getType(): Int {
        return type
    }

    override fun bind(holder: AbsViewHolder) {
        val tv: TextView = holder.mRootView.findViewById(R.id.tv)
        tv.text = content
    }
}

class TestAdapter : AbsAdapter<TestData>()



